package br.edu.unilasalle.simon_api.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.joda.time.DateTime;

public class DateUtil {

	public static Date parse(final String text, final String mask) throws ParseException {
		return new SimpleDateFormat(mask).parse(text);
	}
	
	public static Date getLastHourOfDate(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return getLastHourOfDate(cal);
	}

	public static Date getLastHourOfDate(Calendar cal) {
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		cal.set(Calendar.MILLISECOND, 999);
		return cal.getTime();
	}
	
	public static Date addDaysToDate(Date date, Integer daysToAdd) {
		DateTime dt = new DateTime(date);
		return dt.plusDays(daysToAdd).toDate();
	}
}
